4

本文参考balance-transfer,原文档有些问题会跑不通,做了适度的调整

部署fabric网络并启动fabric-client(nodejs)

下载fabric-samples

cd /opt/gopath/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-samples

启动网络

cd /opt/gopath/src/github.com/hyperledger/fabric-samples/balance-transfer
docker-compose -f artifacts/docker-compose.yaml up

修改package.json

{
  "name": "balance-transfer",
  "version": "1.0.0",
  "description": "A balance-transfer example node program to demonstrate using node.js SDK APIs",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "keywords": [
    "fabric-client sample app",
    "balance-transfer node sample",
    "v1.0 fabric nodesdk sample"
  ],
  "engines": {
    "node": "8.9.4",
    "npm": "5.6.0"
  },
  "license": "Apache-2.0",
  "dependencies": {
    "body-parser": "^1.17.1",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.3",
    "express": "^4.15.2",
    "express-bearer-token": "^2.1.0",
    "express-jwt": "^5.1.0",
    "express-session": "^1.15.2",
    "fabric-ca-client": "^1.0.2",
    "fabric-client": "^1.0.2",
    "fs-extra": "^2.0.0",
    "jsonwebtoken": "^7.3.0",
    "log4js": "^0.6.38"
  }
}

安装node 的fabric-ca-client和fabric-client

node安装并查看版本

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum install -y nodejs
node -v
v8.9.4

查看npm版本

npm -v
5.6.0

安装依赖

npm install node-gyp
npm install node-pre-gyp
npm install grpc
npm install

请安装jq

 yum install jq

启动node服务

PORT=4000 node app

启动日志

[2018-01-31 16:30:13.600] [DEBUG] Helper - [crypto_ecdsa_aes]: constructor, keySize: 256
[2018-01-31 16:30:13.604] [DEBUG] Helper - [crypto_ecdsa_aes]: Hash algorithm: SHA2, hash output size: 256
[2018-01-31 16:30:13.711] [DEBUG] Helper - [utils.CryptoKeyStore]: CryptoKeyStore, constructor - start
[2018-01-31 16:30:13.712] [DEBUG] Helper - [utils.CryptoKeyStore]: constructor, no super class specified, using config: fabric-client/lib/impl/FileKeyValueStore.js
[2018-01-31 16:30:13.718] [DEBUG] Helper - [crypto_ecdsa_aes]: constructor, keySize: 256
[2018-01-31 16:30:13.718] [DEBUG] Helper - [crypto_ecdsa_aes]: Hash algorithm: SHA2, hash output size: 256
[2018-01-31 16:30:13.718] [DEBUG] Helper - [utils.CryptoKeyStore]: CryptoKeyStore, constructor - start
[2018-01-31 16:30:13.719] [DEBUG] Helper - [utils.CryptoKeyStore]: constructor, no super class specified, using config: fabric-client/lib/impl/FileKeyValueStore.js
[2018-01-31 16:30:13.735] [INFO] SampleWebApp - ****************** SERVER STARTED ************************
[2018-01-31 16:30:13.736] [INFO] SampleWebApp - **************  http://localhost:4000  ******************
以上步骤均在runApp.sh中
vim /opt/gopath/src/github.com/hyperledger/fabric-samples/balance-transfer/runApp.sh

使用node API实现操作

注意此时需要http访问了,需要关闭之前的各种proxy

注册和enroll新的user在org1

curl -s -X POST \
  http://localhost:4000/users \
  -H "content-type: application/x-www-form-urlencoded" \
  -d 'username=Barry&orgName=org1'


{"success":true,"secret":"","message":"Barry enrolled Successfully","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw"}

注册和enroll新的user在org2

curl -s -X POST \
  http://localhost:4000/users \
  -H "content-type: application/x-www-form-urlencoded" \
  -d 'username=Barry&orgName=org2'

{"success":true,"secret":"","message":"Barry enrolled Successfully","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2OTcsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMiIsImlhdCI6MTUxNzQ1MDY5N30.YhCQNk3vSeb4hA51cHIUJO9XKiDbiv3N9XnbYHreCz0"}

创建channel

curl -s -X POST \
  http://localhost:4000/channels \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json" \
  -d '{
    "channelName":"mychannel",
    "channelConfigPath":"../artifacts/channel/mychannel.tx"
}'


{"success":true,"message":"Channel 'mychannel' created Successfully"}
注意:authorization Bearer后跟之前的enroll的token

org1加入channel

curl -s -X POST \
  http://localhost:4000/channels/mychannel/peers \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["peer1","peer2"]
}'

{"success":true,"message":"Successfully joined peers in organization org1 to the channel 'mychannel'"}

org2加入channel

curl -s -X POST \
  http://localhost:4000/channels/mychannel/peers \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2OTcsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMiIsImlhdCI6MTUxNzQ1MDY5N30.YhCQNk3vSeb4hA51cHIUJO9XKiDbiv3N9XnbYHreCz0" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["peer1","peer2"]
}'

{"success":true,"message":"Successfully joined peers in organization org2 to the channel 'mychannel'"}

org1 安装channelcode

curl -s -X POST \
  http://localhost:4000/chaincodes \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["peer1", "peer2"],
    "chaincodeName":"mycc",
    "chaincodePath":"github.com/example_cc",
    "chaincodeVersion":"v0"
}'

Successfully Installed chaincode on organization org1
chaincodePath 也可以写成绝对路径
"chaincodePath":"$PWD/artifacts/src/github.com/example_cc/node",

org2 安装channelcode

curl -s -X POST \
  http://localhost:4000/chaincodes \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2OTcsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMiIsImlhdCI6MTUxNzQ1MDY5N30.YhCQNk3vSeb4hA51cHIUJO9XKiDbiv3N9XnbYHreCz0" \
  -H "content-type: application/json" \
  -d '{
    "peers": ["peer1","peer2"],
    "chaincodeName":"mycc",
    "chaincodePath":"github.com/example_cc",
    "chaincodeVersion":"v0"
}'

Successfully Installed chaincode on organization org2

org1 的peer1 实例化channelcode

curl -s -X POST \
  http://localhost:4000/channels/mychannel/chaincodes \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json" \
  -d '{
    "chaincodeName":"mycc",
    "chaincodeVersion":"v0",
    "args":["a","100","b","200"]
}'

Chaincode Instantiation is SUCCESS[

org1的peer1 invoke channelcode

curl -s -X POST \
  http://localhost:4000/channels/mychannel/chaincodes/mycc \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json" \
  -d '{
    "fcn":"move",
    "args":["a","b","10"]
}'


1f0d78257600c8d22496cf44bfc258d0636df4701b908b74bd5fd4c7fee5271f

查询chaincode

curl -s -X GET \
  "http://localhost:4000/channels/mychannel/chaincodes/mycc?peer=peer1&fcn=query&args=%5B%22a%22%5D" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json"

a now has 90 after the move

根据区块号码查询

curl -s -X GET \
  "http://localhost:4000/channels/mychannel/blocks/1?peer=peer1" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json"

输出

{"header":{"number":"1","previous_hash":"0664200ce99ba01be091fb55851c0b133c03c3f4504af24933d8317944865296","data_hash":"a4a60217882efdf2db7a1097d5455d14b3ab25eef38e7f12ac8cb013240abc19"},"data":{"data":[{"signature":{"type":"Buffer","data":[48,68,2,32,97,85,177,47,70,144,22,46,203,89,202,86,124,35,83,222,85,34,54,140,247,96,10,139,119,64,22,151,29,250,66,140,2,32,87,35,167,167,75,143,248,48,50,250,47,183,220,69,48,102,235,125,102,107,75,148,60,67,31,222,117,54,60,29,43,2]},"payload":{"header":{"channel_header":{"type":3,"version":1,"timestamp":"Thu Feb 01 2018 10:11:16 GMT+0800 (CST)","channel_id":"mychannel","tx_id":"246179ff7cceaabdc34811dafdb15b07a7b84270375f0e51bf34e8ded8f9b35d","epoch":"0","extension":{"type":"Buffer","data":[18,6,18,4,108,115,99,99]},"typeString":"ENDORSER_TRANSACTION"},"signature_header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----\nMIICGTCCAb+gAwIBAgIQKKKdQSzsDoUYn/LPAuRWGTAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDDBZBZG1pbkBvcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAECmbzUDozIrLKjp3OAzItSG7m7Flw76rT\n8VO8E6otlCwxKtBRkPpZL7norC3NsjyE339J5O4pXCqhIApQyRRsRqNNMEswDgYD\nVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE\nyKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDSAAwRQIhALT02pc/\nyfE/4wUJfUBQ32GifUEh8JktAXzL/73S0rjYAiACNSp6zAQBX9SBxTOGMk4cGGAy\nCKqf8052NVUs2CvPzA==\n-----END CERTIFICATE-----\n"},"nonce":{"type":"Buffer","data":[253,239,177,254,29,27,96,216,175,70,231,198,247,91,170,113,52,220,37,224,111,172,59,126]}}},"data":{"actions":[{"header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----\nMIICGTCCAb+gAwIBAgIQKKKdQSzsDoUYn/LPAuRWGTAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDDBZBZG1pbkBvcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAECmbzUDozIrLKjp3OAzItSG7m7Flw76rT\n8VO8E6otlCwxKtBRkPpZL7norC3NsjyE339J5O4pXCqhIApQyRRsRqNNMEswDgYD\nVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE\nyKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDSAAwRQIhALT02pc/\nyfE/4wUJfUBQ32GifUEh8JktAXzL/73S0rjYAiACNSp6zAQBX9SBxTOGMk4cGGAy\nCKqf8052NVUs2CvPzA==\n-----END CERTIFICATE-----\n"},"nonce":{"type":"Buffer","data":[253,239,177,254,29,27,96,216,175,70,231,198,247,91,170,113,52,220,37,224,111,172,59,126]}},"payload":{"chaincode_proposal_payload":{"input":{"type":"Buffer","data":[10,73,8,1,18,6,18,4,108,115,99,99,26,61,10,6,100,101,112,108,111,121,10,9,109,121,99,104,97,110,110,101,108,10,40,10,38,8,1,18,10,18,4,109,121,99,99,26,2,118,48,26,22,10,4,105,110,105,116,10,1,97,10,3,49,48,48,10,1,98,10,3,50,48,48]}},"action":{"proposal_response_payload":{"proposal_hash":"6f09f4dbadb24adcafe38425cfc5f103fb79330513e5267fda8f0b2a56882aad","extension":{"results":{"data_model":0,"ns_rwset":[{"namespace":"lscc","rwset":{"reads":[{"key":"mycc","version":null}],"range_queries_info":[],"writes":[{"key":"mycc","is_delete":false,"value":"\n\u0004mycc\u0012\u0002v0\u001a\u0004escc\"\u0004vscc*(\u0012\f\u0012\n\b\u0001\u0012\u0002\b\u0000\u0012\u0002\b\u0001\u001a\u000b\u0012\t\n\u0007Org1MSP\u001a\u000b\u0012\t\n\u0007Org2MSP2D\n ����ϧ�i?v��OCjˢ��\"��Hq\u001e��Gb\u0012 *PI�w�\u000fjL5x6^�E=�)ˡF��\t\u0019\u0015��C5\u00115: ���ԣV��k����ر���\u000b>z!F�P\"�+΋I�B,\u0012\f\u0012\n\b\u0001\u0012\u0002\b\u0000\u0012\u0002\b\u0001\u001a\r\u0012\u000b\n\u0007Org1MSP\u0010\u0001\u001a\r\u0012\u000b\n\u0007Org2MSP\u0010\u0001"}]}},{"namespace":"mycc","rwset":{"reads":[],"range_queries_info":[],"writes":[{"key":"a","is_delete":false,"value":"100"},{"key":"b","is_delete":false,"value":"200"}]}}]},"events":{"chaincode_id":"","tx_id":"","event_name":"","payload":{"type":"Buffer","data":[]}},"response":{"status":200,"message":"","payload":"\n\u0004mycc\u0012\u0002v0\u001a\u0004escc\"\u0004vscc*(\u0012\f\u0012\n\b\u0001\u0012\u0002\b\u0000\u0012\u0002\b\u0001\u001a\u000b\u0012\t\n\u0007Org1MSP\u001a\u000b\u0012\t\n\u0007Org2MSP2D\n ����ϧ�i?v��OCjˢ��\"��Hq\u001e��Gb\u0012 *PI�w�\u000fjL5x6^�E=�)ˡF��\t\u0019\u0015��C5\u00115: ���ԣV��k����ر���\u000b>z!F�P\"�+΋I�B,\u0012\f\u0012\n\b\u0001\u0012\u0002\b\u0000\u0012\u0002\b\u0001\u001a\r\u0012\u000b\n\u0007Org1MSP\u0010\u0001\u001a\r\u0012\u000b\n\u0007Org2MSP\u0010\u0001"},"chaincode_id":{"path":"","name":"lscc","version":"1.0.6-snapshot-78e18d1"}}},"endorsements":[{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----\nMIICGDCCAb+gAwIBAgIQPcMFFEB/vq6mEL6vXV7aUTAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzS9k2gCKHcat8Wj4T2nB1uyC8R2zg3um\nxdTL7nmgFWp0uyCCbQQxD/VS+8R/3DNvEFkvzhcjc9NU/nRqMirpLqNNMEswDgYD\nVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE\nyKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDRwAwRAIgHBdxbHUG\nrFUzKPX9UmmN3SwigWcRUREUy/GTb3hDIAsCIEF1BxTqv8ilQYE8ql0wJL4mTber\nHE6DFYvvBCUnicUh\n-----END -----\n"},"signature":{"type":"Buffer","data":[48,69,2,33,0,221,89,84,65,198,9,182,185,236,115,245,0,126,215,99,202,175,124,30,19,85,188,93,198,107,180,1,120,31,49,151,223,2,32,13,83,183,254,68,247,90,114,116,100,211,167,147,77,7,114,143,119,1,189,118,59,212,226,6,154,183,85,0,17,205,98]}},{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----\nMIICGjCCAcCgAwIBAgIRAI+BBtEBvpOqhfRZZH7eV/YwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNjIzMTIzMzE5WhcNMjcwNjIxMTIzMzE5\nWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzEfMB0GA1UEAxMWcGVlcjEub3JnMS5leGFtcGxlLmNvbTBZ\nMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCnT04ltvjsgiZVuCGLsRYzEiCTJZlZw\nh3HT/273B3NkWA7wrlyK7FfAanIyexuR1UI9m4+YKNqFG6cgYnf8MsejTTBLMA4G\nA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIA5ykiTos/MX\nhMipPFuO9vTByR2ebld8RcMxY2Cf5AARMAoGCCqGSM49BAMCA0gAMEUCIQCSRdWm\ni4IgVUajvzWVxyE/wi7n617pVqS4+nJ7gbTRjQIgefzBwS+bkNhPc3/rktySFLRC\nWMnq87KyqMLc6iRaJx0=\n-----END -----\n"},"signature":{"type":"Buffer","data":[48,69,2,33,0,199,231,180,29,203,81,149,143,127,66,155,2,123,159,37,68,254,129,236,250,170,122,254,193,94,166,237,95,180,197,25,111,2,32,36,33,111,115,225,188,10,156,46,238,37,118,76,149,185,157,167,63,115,123,150,114,58,226,65,26,118,66,97,211,208,43]}}]}}}]}}}]},"metadata":{"metadata":[{"value":"","signatures":[{"signature_header":{"creator":{"Mspid":"OrdererMSP","IdBytes":"-----BEGIN -----\nMIICDTCCAbOgAwIBAgIRALFafJiTFN/47AvAGfvj1ZEwCgYIKoZIzj0EAwIwaTEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRcwFQYDVQQDEw5jYS5leGFt\ncGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTlaMFgxCzAJBgNV\nBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp\nc2NvMRwwGgYDVQQDExNvcmRlcmVyLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYI\nKoZIzj0DAQcDQgAEYtguLKFBLLc0VSwyPHHHNe76HH71oOXK6wun8Y/5vtMawPZ/\nWTm/vBVUWdfNlzc9eA28aXx6zBAB8iRm16EeU6NNMEswDgYDVR0PAQH/BAQDAgeA\nMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDUbM8OlDbBvDtuK/gM2yAsSUNgT5\nXHLuD/g50+wwBxkwCgYIKoZIzj0EAwIDSAAwRQIhANJuEGHBftrtlWgie9zgc60J\n/XVytPN/D0rPlkMV17n7AiBBbStggGBfFYcQ2LhDhcKut8nScJ2OFrt+dJSdJbod\n7A==\n-----END -----\n"},"nonce":{"type":"Buffer","data":[23,194,242,143,221,90,72,166,151,0,135,49,136,64,157,226,109,131,36,120,189,18,37,195]}},"signature":{"type":"Buffer","data":[48,69,2,33,0,194,79,89,128,252,88,27,94,211,26,101,215,142,220,38,84,189,91,165,231,173,88,107,234,96,50,238,167,76,69,71,96,2,32,25,181,163,165,231,163,133,128,75,193,230,133,65,115,154,244,141,14,119,240,46,15,65,198,101,53,130,111,12,3,74,59]}}]},{"value":{"index":"0"},"signatures":[{"signature_header":{"creator":{"Mspid":"OrdererMSP","IdBytes":"-----BEGIN -----\nMIICDTCCAbOgAwIBAgIRALFafJiTFN/47AvAGfvj1ZEwCgYIKoZIzj0EAwIwaTEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRcwFQYDVQQDEw5jYS5leGFt\ncGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTlaMFgxCzAJBgNV\nBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp\nc2NvMRwwGgYDVQQDExNvcmRlcmVyLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYI\nKoZIzj0DAQcDQgAEYtguLKFBLLc0VSwyPHHHNe76HH71oOXK6wun8Y/5vtMawPZ/\nWTm/vBVUWdfNlzc9eA28aXx6zBAB8iRm16EeU6NNMEswDgYDVR0PAQH/BAQDAgeA\nMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDUbM8OlDbBvDtuK/gM2yAsSUNgT5\nXHLuD/g50+wwBxkwCgYIKoZIzj0EAwIDSAAwRQIhANJuEGHBftrtlWgie9zgc60J\n/XVytPN/D0rPlkMV17n7AiBBbStggGBfFYcQ2LhDhcKut8nScJ2OFrt+dJSdJbod\n7A==\n-----END -----\n"},"nonce":{"type":"Buffer","data":[69,152,26,2,158,39,123,106,137,249,50,166,48,82,137,238,62,45,137,151,93,94,54,208]}},"signature":{"type":"Buffer","data":[48,68,2,32,37,123,47,42,244,219,141,199,92,221,204,87,96,3,205,200,146,23,241,119,5,64,47,216,169,95,17,48,196,190,205,28,2,32,105,8,79,181,140,29,230,153,118,242,153,49,229,116,244,129,84,2,28,242,124,151,59,179,66,113,35,183,114,112,4,176]}}]},[0]]}}[root@block-hubin-104 balance-transfer]

根据transactionID查询交易

transactions/后的字符为invoke返回的transactionID

curl -s -X GET http://localhost:4000/channels/mychannel/transactions/1f0d78257600c8d22496cf44bfc258d0636df4701b908b74bd5fd4c7fee5271f?peer=peer1 \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json"

输出

{"validationCode":0,"transactionEnvelope":{"signature":{"type":"Buffer","data":[48,69,2,33,0,185,163,80,179,245,219,65,184,204,163,115,254,248,52,65,176,193,29,69,88,248,66,171,180,44,148,52,220,12,16,95,186,2,32,66,37,236,145,58,181,14,60,224,129,23,254,51,113,208,91,159,215,73,48,249,128,243,142,241,123,243,183,38,134,165,28]},"payload":{"header":{"channel_header":{"type":3,"version":1,"timestamp":"Thu Feb 01 2018 10:13:49 GMT+0800 (CST)","channel_id":"mychannel","tx_id":"1f0d78257600c8d22496cf44bfc258d0636df4701b908b74bd5fd4c7fee5271f","epoch":"0","extension":{"type":"Buffer","data":[18,6,18,4,109,121,99,99]},"typeString":"ENDORSER_TRANSACTION"},"signature_header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----\nMIIB8DCCAZegAwIBAgIUFJ+NHGFxRg73T+233rHsujLqMyEwCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwMTMxMTExMDAwWhcNMTkwMTMxMTEx\nMDAwWjAQMQ4wDAYDVQQDEwVhZG1pbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBPYeeBj5ssSFu6H4qvA4WzHyV1Utss0GJF2PGTP6lH5+tJN8d/7YZJmykUXIZoU1\nAcYxAH4QbLPVwk1/En98rsmjbDBqMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8E\nAjAAMB0GA1UdDgQWBBQobo0nZvSn6whePOc+1dryxiGPhjArBgNVHSMEJDAigCAO\ncpIk6LPzF4TIqTxbjvb0wckdnm5XfEXDMWNgn+QAETAKBggqhkjOPQQDAgNHADBE\nAiB4zornAF0Qt1nRYtzJq5AN8DDGN9sl6vwuMg9LmowMkAIgdcxa8TUIXy5aRNoU\nUXR4U2CzKiNlQQX/HXsJIDgx9DI=\n-----END CERTIFICATE-----\n"},"nonce":{"type":"Buffer","data":[20,39,188,238,82,73,112,68,30,209,206,164,185,253,245,103,138,255,175,176,80,102,210,76]}}},"data":{"actions":[{"header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----\nMIIB8DCCAZegAwIBAgIUFJ+NHGFxRg73T+233rHsujLqMyEwCgYIKoZIzj0EAwIw\nczELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh\nbiBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT\nE2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwMTMxMTExMDAwWhcNMTkwMTMxMTEx\nMDAwWjAQMQ4wDAYDVQQDEwVhZG1pbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBPYeeBj5ssSFu6H4qvA4WzHyV1Utss0GJF2PGTP6lH5+tJN8d/7YZJmykUXIZoU1\nAcYxAH4QbLPVwk1/En98rsmjbDBqMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8E\nAjAAMB0GA1UdDgQWBBQobo0nZvSn6whePOc+1dryxiGPhjArBgNVHSMEJDAigCAO\ncpIk6LPzF4TIqTxbjvb0wckdnm5XfEXDMWNgn+QAETAKBggqhkjOPQQDAgNHADBE\nAiB4zornAF0Qt1nRYtzJq5AN8DDGN9sl6vwuMg9LmowMkAIgdcxa8TUIXy5aRNoU\nUXR4U2CzKiNlQQX/HXsJIDgx9DI=\n-----END CERTIFICATE-----\n"},"nonce":{"type":"Buffer","data":[20,39,188,238,82,73,112,68,30,209,206,164,185,253,245,103,138,255,175,176,80,102,210,76]}},"payload":{"chaincode_proposal_payload":{"input":{"type":"Buffer","data":[10,28,8,1,18,6,18,4,109,121,99,99,26,16,10,4,109,111,118,101,10,1,97,10,1,98,10,2,49,48]}},"action":{"proposal_response_payload":{"proposal_hash":"d2ea3d2fa713c24eaaa2513a47d85d004877004fa0acfa11cee1f0106611a6ea","extension":{"results":{"data_model":0,"ns_rwset":[{"namespace":"lscc","rwset":{"reads":[{"key":"mycc","version":{"block_num":"1","tx_num":"0"}}],"range_queries_info":[],"writes":[]}},{"namespace":"mycc","rwset":{"reads":[{"key":"a","version":{"block_num":"1","tx_num":"0"}},{"key":"b","version":{"block_num":"1","tx_num":"0"}}],"range_queries_info":[],"writes":[{"key":"a","is_delete":false,"value":"90"},{"key":"b","is_delete":false,"value":"210"}]}}]},"events":{"chaincode_id":"","tx_id":"","event_name":"","payload":{"type":"Buffer","data":[]}},"response":{"status":200,"message":"","payload":""},"chaincode_id":{"path":"","name":"mycc","version":"v0"}}},"endorsements":[{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----\nMIICGDCCAb+gAwIBAgIQPcMFFEB/vq6mEL6vXV7aUTAKBggqhkjOPQQDAjBzMQsw\nCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy\nYW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu\nb3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla\nMFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T\nYW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzS9k2gCKHcat8Wj4T2nB1uyC8R2zg3um\nxdTL7nmgFWp0uyCCbQQxD/VS+8R/3DNvEFkvzhcjc9NU/nRqMirpLqNNMEswDgYD\nVR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE\nyKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDRwAwRAIgHBdxbHUG\nrFUzKPX9UmmN3SwigWcRUREUy/GTb3hDIAsCIEF1BxTqv8ilQYE8ql0wJL4mTber\nHE6DFYvvBCUnicUh\n-----END -----\n"},"signature":{"type":"Buffer","data":[48,69,2,33,0,249,84,44,238,169,234,246,112,83,154,147,200,71,174,225,91,223,98,228,210,51,247,134,221,199,145,133,220,190,176,85,153,2,32,45,141,102,182,9,197,12,56,249,79,249,34,173,165,15,112,74,169,90,92,172,202,10,140,41,214,82,28,112,175,31,135]}},{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----\nMIICGjCCAcCgAwIBAgIRAI+BBtEBvpOqhfRZZH7eV/YwCgYIKoZIzj0EAwIwczEL\nMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG\ncmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh\nLm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNjIzMTIzMzE5WhcNMjcwNjIxMTIzMzE5\nWjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN\nU2FuIEZyYW5jaXNjbzEfMB0GA1UEAxMWcGVlcjEub3JnMS5leGFtcGxlLmNvbTBZ\nMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCnT04ltvjsgiZVuCGLsRYzEiCTJZlZw\nh3HT/273B3NkWA7wrlyK7FfAanIyexuR1UI9m4+YKNqFG6cgYnf8MsejTTBLMA4G\nA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIA5ykiTos/MX\nhMipPFuO9vTByR2ebld8RcMxY2Cf5AARMAoGCCqGSM49BAMCA0gAMEUCIQCSRdWm\ni4IgVUajvzWVxyE/wi7n617pVqS4+nJ7gbTRjQIgefzBwS+bkNhPc3/rktySFLRC\nWMnq87KyqMLc6iRaJx0=\n-----END -----\n"},"signature":{"type":"Buffer","data":[48,69,2,33,0,234,123,146,118,155,128,29,31,176,19,80,142,135,211,198,228,189,121,250,254,79,223,113,85,238,86,197,34,27,233,216,234,2,32,15,29,170,18,231,45,127,148,95,146,50,210,254,111,226,145,171,19,237,10,168,26,226,162,220,50,112,9,98,61,178,15]}}]}}}]}}}}

获取ChainInfo

curl -s -X GET \
  "http://localhost:4000/channels/mychannel?peer=peer1" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json"

输出

{"height":{"low":3,"high":0,"unsigned":true},"currentBlockHash":{"buffer":{"type":"Buffer","data":[8,3,18,32,197,45,10,52,42,69,183,241,206,187,72,115,41,197,25,220,101,13,133,178,192,130,203,49,150,130,199,51,224,114,147,181,26,32,6,34,252,157,31,20,133,0,176,165,122,234,70,41,158,181,5,225,90,55,187,181,60,108,138,19,28,23,92,193,58,216]},"offset":4,"markedOffset":-1,"limit":36,"littleEndian":true,"noAssert":false},"previousBlockHash":{"buffer":{"type":"Buffer","data":[8,3,18,32,197,45,10,52,42,69,183,241,206,187,72,115,41,197,25,220,101,13,133,178,192,130,203,49,150,130,199,51,224,114,147,181,26,32,6,34,252,157,31,20,133,0,176,165,122,234,70,41,158,181,5,225,90,55,187,181,60,108,138,19,28,23,92,193,58,216]},"offset":38,"markedOffset":-1,"limit":70,"littleEndian":true,"noAssert":false}}

获取已安装的chaincode

curl -s -X GET \
  "http://localhost:4000/chaincodes?peer=peer1&type=installed" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json"

["name: mycc, version: v0, path: github.com/example_cc"]

获取已实例化的chaincode

curl -s -X GET \
  "http://localhost:4000/chaincodes?peer=peer1&type=instantiated" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json"

["name: mycc, version: v0, path: github.com/example_cc"]

获取channels

curl -s -X GET \
  "http://localhost:4000/channels?peer=peer1" \
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" \
  -H "content-type: application/json"

{"channels":[{"channel_id":"mychannel"}]}

mumubin
375 声望185 粉丝